package com.anytron.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.anytron.base.service.impl.BaseServiceImpl;
import com.anytron.mapper.AppInfoMapper;
import com.anytron.mapper.AppTimerMapper;
import com.anytron.model.AppInfo;
import com.anytron.model.AppTimer;
import com.anytron.model.req.PageRequest;
import com.anytron.service.AppTimerService;
import com.github.pagehelper.PageInfo;

import tk.mybatis.mapper.entity.Example;

@Service
public class AppTimerServiceImpl extends BaseServiceImpl<AppTimer> implements AppTimerService {

	@Autowired
	AppInfoMapper appInfoMapper;

	@Autowired
	public void setMapper(AppTimerMapper mapper) {
		this.mapper = mapper;
	}

	@Override
	public PageInfo<AppTimer> queryDataByPage(PageRequest pageRequest, AppTimer appTimer) {
		Example example = new Example(AppTimer.class);
		Example.Criteria criteria = example.createCriteria();
		example.setOrderByClause("app_id asc");
		if (appTimer.getAppId() != null && appTimer.getAppId() > 0) {
			criteria.andEqualTo("appId", appTimer.getAppId());
		}
		PageInfo<AppTimer> pageInfo = pageByExample(pageRequest, example);
		pageInfo.getList().forEach(item -> {
			AppInfo appInfo = appInfoMapper.selectByPrimaryKey(item.getAppId());
			if (appInfo != null) {
				item.setAppName(appInfo.getAppName());
			}
		});
		return pageInfo;
	}

}
